<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>按键获得光标</title>
</head>
<body>
    <input type="text">
    <script>
        var search = document.querySelector('input');
        // keydown 会输入按键内容  keyup 不会
        document.addEventListener('keyup',function(e) {
            // 判断是否按下的是s 键
            if (e.keyCode === 83) {
                // 是则input 获得光标
                search.focus();
            }
        })
    </script>
</body>
</html>